package cn.itcast.bos.web.action.take_delivery;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;

import cn.itcast.bos.domain.take_delivery.Order;
import cn.itcast.bos.service.take_delivery.OrderService;
import cn.itcast.bos.web.action.common.BaseAction;

@Namespace("/")
@ParentPackage("struts-default")
@Scope("prototype")
@Controller
public class OrderAction extends BaseAction<Order>{
	private static final long serialVersionUID = 1L;

	@Autowired
	private OrderService orderService;
	
	@Action(value = "Order_findByOrderNum")
	public void findByOrderNum() throws IOException {
		Order order = orderService.findByOrderNum(model.getOrderNum());
		Map<String, Object> result = new HashMap<String, Object>();
		if(order!=null){
			result.put("success", true);
			result.put("orderData", order);
			String jsonString = JSONArray.toJSONString(result, SerializerFeature.DisableCircularReferenceDetect);
			ServletActionContext.getResponse().setContentType("application/json;charset=utf-8");
			ServletActionContext.getResponse().getWriter().write(jsonString);
			System.out.println(jsonString);
		}else{
			result.put("success", false);
		}
	}
}
